package com.runningboy.springboot_jms.queue;

import com.runningboy.springboot_jms.ActivemqConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Destination;
import javax.jms.Queue;
import javax.jms.Topic;
import java.util.UUID;

/**
 * @Description: 生产者
 * @Author Runningboy
 * @Date 2020/7/25 20:56
 * @Version 1.0
 */
@RestController
public class ProducerSendMessageController {

    @Autowired
    private Queue queue;

    @Autowired
    private Topic topic;

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    /**
     * 发送 队列消息
     * @return
     */
    @RequestMapping("/sendQueue")
    public String sendQueue(){
        String message = "mq-queue"+UUID.randomUUID().toString();
        //指定消息发送的目的地及内容
        jmsMessagingTemplate.convertAndSend(this.queue,message);
        return "队列消息发送成功！message="+message;
    }

    /**
     * 发送 主题消息
     * @return
     */
    @RequestMapping("/sendTopic")
    public String sendTopic(){
        String message = "mq-topic"+UUID.randomUUID().toString();
        //指定消息发送的目的地及内容
        jmsMessagingTemplate.convertAndSend(this.topic,message);
        return "主题消息发送成功！message="+message;
    }
}
